<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * database_helper
 *
 * @author Simon Emms <simon@simonemms.com>
 */


/**
 * Can Connect DB
 * 
 * Checks if the given database type can
 * connect.  Checks that the 
 * @param type $type
 * @return type 
 */
function can_connect_db($type) {
    
    $type = strtolower($type);
    
    switch($type) {
        case 'cubrid':
            /* Cubrid */
            $function = 'cubrid_connect';
            break;
        
        case 'mssql':
            /* MS SQL */
            $function = 'mssql_connect';
            break;
        
        case 'oci8':
            /* OCI8 */
            $function = 'oci_connect';
            break;
        
        case 'odbc':
            /* ODB */
            $function = 'odbc_connect';
            break;
        
        case 'pdo':
            /* PDO - works differently to the rest */
            return class_exists('PDO');
            break;
        
        case 'postgre':
            /* PostgreSQL */
            $function = 'pg_connect';
            break;
        
        case 'sqlite':
            /* SQLite */
            $function = 'sqlite_open';
            break;
        
        case 'sqlsrv':
            /* SQL Azure */
            $function = 'sqlsrv_connect';
            break;
        
        case 'mysql':
        case 'mysqli':
            /* MySQL */
            $function = 'mysql_connect';
            break;
        
        default:
            /* Not available */
            return false;
    }
    
    return function_exists($function);
    
}
?>